﻿using System.Drawing;
using System.Windows.Forms;
using XFControls.Utils;

namespace XFControls.XFPanels
{
    public class XFPanelIconBottom
    {
        public bool MagnifyingGlass { get; set; }
        public bool Album { get; set; }

        private int padding = 16;
        private int diameter = 6;

        public void Draw(Graphics g, int y, int height, int page, int pages)
        {
            int width = Screen.PrimaryScreen.WorkingArea.Width;
            Point center = new Point(width >> 1, y + (height >> 1));
            int mid = pages >> 1;

            int start = center.X;
            if (pages % 2 != 0)
            {
                start -= mid * (padding + diameter);
                start -= diameter >> 1;
            }
            else
            {
                start -= (mid - 1) * (padding + diameter);
                start -= (padding >> 1) + diameter;
            }

            for (int i = 0; i < pages; i++)
            {
                Rectangle rec = new Rectangle(start, center.Y, diameter, diameter);
                start += diameter + padding;

                Color fill = Color.Gray;
                if (i == page)
                {
                    rec.X -= 2;
                    rec.Y -= 2;
                    rec.Height += 4;
                    rec.Width += 4;

                    fill = Color.Black;
                }
                if (i == 0 && MagnifyingGlass)
                    DrawUI(i == page ? "magnifying_glass_selected" : "magnifying_glass", g, rec, true);
                else if (i == pages - 1 && Album)
                    DrawUI(i == page ? "album_selected" : "album", g, rec, true);
                else
                    using (SolidBrush b = new SolidBrush(fill))
                        g.FillEllipse(b, rec);
            }
        }

        public void DrawUI(string uri, Graphics g, Rectangle rec, bool maintainImgRatio)
        {
            rec.Y -= 2;
            
            var ms = XFGraphics.GetMemoryAssembly(this, uri);
            if (ms == null) return;

            byte[] buffer = ms.GetBuffer();

            if (buffer == null) return;

            XFGraphics.DrawMemoryStream(g, rec.X, rec.Y, buffer);
        }

    }
}